<%--
    fileName      : /prodmanage/allfile.jsp
    author        : lenovo
    createDate    : 2016-04-26  
    lastModifier  : lenovo
    lastModifyDate: 2016-04-26       
    description   : 全部附件列表页面
--%>
<%@ page language='java' contentType='text/html; charset=UTF-8' pageEncoding='UTF-8' %>
<%@ taglib uri='ctp-tag' prefix='ctp' %>
<%@ page import="com.icbc.cte.base.CTEConstance" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
        <title></title>
        <ctp:include items='public,validator,groupbox,borderlayout,panel,form,button,toolbar,gridlayout,label,textfield,combobox,checkboxgroup,datepicker,grid,menus,chain,messagebox,link'/>
<%
 String proId = String.valueOf(request.getParameter("proId"));
 String labelId = String.valueOf(request.getParameter("labelId"));
 String file_save_path = "";
 	try{
	    file_save_path= CTEConstance.getEnvProperty("file_save_path");
 	}catch(Exception e){
 		file_save_path = "";
 	}
%>
        <script type='text/javascript' kind='variant'>

            var borderlayout1;
            var querycondition;       //查询条件
            var queryForm;
            var queryGridlayout;
            var reset;                //重置    
            var submit;               //提交
            var v_probaseinfoId = "";		  //方法域中记录问题ID的变量
            var v_urlFirst='';
            var openFrom = '0';
            var queryGroupbox;
            var selectButton;
            var queryGridlayprod;
            var proList;
            var proId = '<%=proId%>';
            var labelId = '<%=labelId%>';
        </script>
        <script type='text/javascript' kind='event'>
            var proListUrl = '<ctp:url href="proinfomain.flowc" flowActionName="queryindexfile"/>&proId='+proId+'&labelId='+labelId;
        	function download(){//文件下载功能
			   	downloadForm.openType.value = "attachment";
				downloadForm.fileName.value = this.filePath;
				downloadForm.showFileName.value = this.fileName;
				downloadForm.submit();
		    }
		    function batchUpload(){
		    	var selects = prolist.getAllSelectedData();
		    	var fileList = new Array();
		    	var fileNameList = new Array();
            	if(selects.length < 1){
            		ctpMSB.alert({message:'<ctp:label key="select_batchUpload_record"/>',title:'<ctp:label key="tips_msg"/>',btn:[['确定','OK']],closeBtn:false});
            		return;
                }
                for (i=0;i<selects.length;i++){
                	fileList.push(selects[i].filePath);
                	fileNameList.push(selects[i].fileName);
                }

                ctp.data.getJSONA({	
					url:'<ctp:url href="proinfomain.flowc" flowActionName="zipfiles"/>',
					reqData:{
						"srcFileNumber":selects.length,
						"srcFilePathField":fileList,
						"srcFileNameField":fileNameList,
						"zipFileNameField":'<%=file_save_path%>' ,
						"bytes":'1' ,
						"encoding":'GBK'
					},
					success :function(data){
								if(data && data[0].retCode =="0"){
									downloadForm.openType.value = "attachment";
									downloadForm.fileName.value = data[0].outFileNameField;
									downloadForm.showFileName.value = data[0].outFileName;
									downloadForm.submit();
								}else if(data && data[0].retCode =="-1"){
									ctpMSB.alert({title:'<ctp:label key="batchUpload.error"/>',message:data[0].retMsg});
								}else {
									ctpMSB.alert({title:'<ctp:label key="batchUpload.error"/>',message:'<ctp:label key="batchUpload.error"/>'});
								}
							}
				});
                
			}
        </script>
        <script type='text/javascript' kind='ui'>

            $(window).load(function(){
                toolbar1 = new ctp.ui.toolbar({
                    id: 'toolbar1',
                    leftItems: [
                        {
                            type: 'button',
                            id: 'batchUpload',
                            name: 'batchUpload',
                            text: '<ctp:label key="batchUpload"/>',//'批量下载',
                            icon: 'down_all',
                            onClick : batchUpload
                        }
                    ]
                });
                prolist = new ctp.ui.grid({
                    id: 'prolist',
                    title:'列表',
                    toolbar:toolbar1,
                    toolbarPos:'innertop',
                    url:proListUrl,
                    header: {
                        title: [
                            [
                                {text: '',width: '150px'}
                                ,								
									{			
										text: '<ctp:label key="file.link"/>'
									},								
									{			
										text: '<ctp:label key="file.uploadtime"/>'
									},
									{			
										text: '<ctp:label key="file.uploaduser"/>'
									},								
									{			
										text: '<ctp:label key="file.indexName"/>'
									}							                                
                            ]
                        ],
                        rowIdFieldName: "id",
                        attr: [
   							{colType: "checkbox"},
							{fieldName: "fileName",
								fieldType: 'link',//生成下载超链接，添加下载方法
			                    fieldAttr:{title:'<ctp:label key="file.download"/>',onClick: download}},//'下载附件'
			                    {fieldName: "postDate" ,css:{"text-align":"center"}},
			                    {fieldName: "postUser",css:{"text-align":"center"}},
			                    {fieldName: "indexName",css:{"text-align":"center"}}
							]
                    }
                });

                borderlayout1 = new ctp.ui.borderlayout({
                    type: '1C',
                    center__size: 1.0,
					center__items:[prolist],
					center__scrollable:true,
                    renderTo: 'body'
                });
            });
        </script>


    </head>
    <body>
     	<ctp:form name="downloadForm" method="post" action="proinfomain.flowc" flowActionName="fileDownload">
			<ctp:hidden name="openType" />
			<ctp:hidden name="fileName" />
			<ctp:hidden name="showFileName" />
        </ctp:form>
    </body>
</html>
